package com.dulichdanang;
import android.app.Activity;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;

public class Map extends Activity implements LocationListener {

	LocationManager locationManager ;
	String provider;
	Double latitude=108.19505914999999,longitude=16.06474635;
	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);        
        Criteria criteria = new Criteria();
        provider = locationManager.getBestProvider(criteria, false);         
        if(provider!=null && !provider.equals("")){
            Location location = locationManager.getLastKnownLocation(provider);          
            locationManager.requestLocationUpdates(provider, 20000, 1, this);
            if(location!=null)
            	onLocationChanged(location);//
            else
            	Toast.makeText(getBaseContext(), "Location can't be retrieved", Toast.LENGTH_SHORT).show();
        }else{
        	Toast.makeText(getBaseContext(), "No Provider Found", Toast.LENGTH_SHORT).show();
        }
    }
	@Override
	public void onLocationChanged(Location location) {
//		TextView tvLongitude = (TextView)findViewById(R.id.tv_longitude);
//		TextView tvLatitude = (TextView)findViewById(R.id.tv_latitude);
		this.latitude = location.getLatitude();
		this.longitude = location.getLongitude();
//		tvLongitude.setText("Longitude:" + this.latitude);
//		tvLatitude.setText("Latitude:" + this.longitude);
	}

	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub		
	}

	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub		
	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub		
	}
	
}
